﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Practices.Unity;
using Praxis.Entities;
using Praxis.BusinessLogic;

namespace Praxis.UI
{
    public partial class FrmEntrega : Form
    {
        [Dependency]
        public IEntregaBL entregaBL { get; set; }

        [Dependency]
        public IAlquilerBL alquilerBL { get; set; }

        [Dependency]
        public IDetalleEntregaBL detEntregaBL { get; set; }

        public FrmEntrega()
        {
            InitializeComponent();
            this.BuildUp();
        }


       

        private void BtnNuevo_Click(object sender, EventArgs e)
        {
            FrmMttoEntrega frm = new FrmMttoEntrega();
            frm.Show();
            this.Hide();
        }

        private void BtnEditar_Click(object sender, EventArgs e)
        {
            FrmMttoEntrega frm = new FrmMttoEntrega();
            frm.Show();
            this.Hide();
        }

        private void FrmEntrega_Load(object sender, EventArgs e)
        {
            eNTREGABindingSource.DataSource = entregaBL.GetAllEntregas();
        }

        private void BtnBuscar_Click(object sender, EventArgs e)
        {
            eNTREGABindingSource.DataSource = entregaBL.GetFromEntregabyCriterio(TxtDescripcion.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dETALLE_ENTREGABindingSource.DataSource = detEntregaBL.GetAllDetalleEntregaByCliente(TxtDescripcion.Text);
        }

        public ENTREGA CurrentEntrega { get; set; }

        private void eNTREGADataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            CurrentEntrega = eNTREGABindingSource.Current as ENTREGA;
        }

        private void eNTREGADataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void eNTREGADataGridView_DoubleClick(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TxtDescripcion_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                eNTREGABindingSource.DataSource = entregaBL.GetFromEntregabyCriterio(TxtDescripcion.Text);
            }
        }

        private void TxtDescripcion_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsLetter(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsSeparator(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        
    }
}
